﻿using System;
using System.Windows.Forms;

namespace Health
{
    public partial class Form1 : Form
    {
        private GradeSelection _gradeSelection = new GradeSelection();
        public Form1()
        {
            InitializeComponent();
        }

        private void btnWoman_Click(object sender, EventArgs e)
        {
            var woman = new Woman(txtWomanName.Text, int.Parse(txtWomanWeight.Text));
            woman.Accept(_gradeSelection);
        }

        private void btnMan_Click(object sender, EventArgs e)
        {
            var woman = new Man(txtManName.Text, int.Parse(txtManHeight.Text));
            woman.Accept(_gradeSelection);
        }
    }


    public class Woman : IElement
    {
        public Woman(string name, int weight)
        {
            Name = name;
            Weight = weight;
        }
        public string Name { get; set; }
        /// <summary>
        /// 体重
        /// </summary>
        public int Weight { get; set; }

        public void Accept(IVisitor visitor)
        {
            visitor.Visit(this);
        }
    }
    public class Man : IElement
    {
        public Man(string name, int height)
        {
            Name = name;
            Height = height;
        }
        public string Name { get; set; }

        /// <summary>
        /// 身高
        /// </summary>
        public int Height { get; set; }

        public void Accept(IVisitor visitor)
        {
            visitor.Visit(this);
        }
    }

    public interface IVisitor
    {
        void Visit(Woman woman);
        void Visit(Man man);
    }

    public class GradeSelection : IVisitor
    {
        public void Visit(Woman woman)
        {
            //重大于50kg
            if (woman.Weight > 50)
            {
                MessageBox.Show(woman.Name + "不健康");
            }
            else
            {
                MessageBox.Show(woman.Name + " is good");
            }
        }

        public void Visit(Man man)
        {
            //身高低于170cm
            if (man.Height < 170)
            {
                MessageBox.Show(man.Name + " 不健康");
            }
            else
            {
                MessageBox.Show(man.Name + " is good");
            }
        }
    }

    public interface IElement
    {
        void Accept(IVisitor visitor);
    }

}
